package net.viral.struts2;

import java.sql.ResultSet;
import java.util.ArrayList;

public class shownews {
	private String title;
	private String description;
	private String author;
	private String link;
	private int flag;
	private String name="null";

	public void setTitle(String title) {
		this.title = title;
	}

	public String getTitle() {
		return title;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return description;
	}

	public void setLink(String link) {
		this.link = link;
	}

	public String getLink() {
		return link;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getAuthor() {
		return author;
	}

	private ArrayList<shownews> news = new ArrayList<shownews>();

	public ArrayList<shownews> getNews() {
		return news;
	}

	public void setNews(ArrayList<shownews> news) {
		this.news = news;
	}

	public String execute() {
		try {
			// System.out.println(category+"  "+date+"  "+time+"  "+description);
			Connect c = new Connect();
			String strQuery = null;
			if(!name.equals("null"))
			{
			strQuery = "select * from feedmessage where category='"+name+"' order by time desc limit 20";
			}
			else
			{
				strQuery = "select * from feedmessage order by time desc limit 20";
			}
			ResultSet rs = c.getResult(strQuery);
			while (rs.next()) {
				shownews sn = new shownews();
				sn.setTitle(rs.getString(2));
				sn.setDescription(rs.getString(3));
				sn.setAuthor(rs.getString(4));
				sn.setLink(rs.getString(1));
				System.out.println("title : " + rs.getString(2)
						+ " Author : " + rs.getString(3));
				news.add(sn);
			}
		} catch (Exception e) {
			System.out.println("error occured here while getting from database");
		}
		return "success";
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setFlag(int flag) {
		this.flag = flag;
	}

	public int getFlag() {
		return flag;
	}
}
